/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.anhndt.audiobook.entity;

import com.anhndt.audiobook.utils.StringUtil;
import com.anhndt.audiobook.utils.Util;
import java.util.Vector;

/**
 *
 * @author Sun
 */
public class ItemPartEntity extends ItemEntity {
    private long partSize;
    private int duration;
    private boolean playing, paused;

    public ItemPartEntity(String id, String other) {
        this.id = id;
        Vector vt = StringUtil.split(other, "/");
        duration = Integer.parseInt(vt.elementAt(0).toString());
        partSize = Integer.parseInt(vt.elementAt(1).toString());
    }
    public ItemPartEntity(String id, String name, String description, String thumbnail, String marked, int rate, String url, String other, String contentType, int counterChild) {
        super(id, name, description, thumbnail, marked, rate, url, other, contentType, counterChild);

        //TODO hard code
//        other = "120/1248587";
        Vector vt = StringUtil.split(other, "/");
        duration = Integer.parseInt(vt.elementAt(0).toString());
        partSize = Integer.parseInt(vt.elementAt(1).toString());
    }

    public String getPartUrl() {
        //http://localhost/audiows/audiofile.aspx?u={0}&a={1}&p={2}
        return StringUtil.format(Util.AUDIO_FILE_URL, new String[] {Util.userID, getParent().id, id,"0"});
    }
  
    public int getDuration() {
        return duration;
    }

    public long getPartSize() {
        return partSize;
    }

    public boolean isPaused() {
        return paused;
    }

    public void setPaused(boolean paused) {
        this.playing = paused ? false : playing;
        this.paused = paused;
    }

    public boolean isPlaying() {
        return playing;
    }

    public void setPlaying(boolean playing) {
        this.playing = playing;
        paused = (playing) ? false : paused;
    }
}
